package com.itheima.mp.controller;

import com.itheima.mp.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired(required = false)
    HelloService helloService;

    @GetMapping("/test")
    public String testHello () {
        String hello = null;
        try {
            Thread.sleep(1000);
            hello = helloService.sayHi("hello world");
            System.out.println("hello param is : " + hello);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return hello != null ? hello : "error";
    }
    @GetMapping("/testtwo")
    public void testHello2 () {
        String hello = null;
        try {
            Thread.sleep(1000);
            helloService.sayHiVoidReturn("hello world");
            System.out.println("hello param is : " + hello);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    @GetMapping("/testSome")
    public String doHttpGet(String uri, Map<String, String> getParams) {
//        TestUtils testUtils = new TestUtils();
        String s = "testUtils.testSome()";
        System.out.println("testUtils.testSome return is:" + s);
//        CloseableHttpResponse response = null;
        return s;
    }
}
